/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package search2;

import env.Action;
import env.Enviroment;
import env.Orientation;
import env.Tile;

/**
 * 
 * @author user
 */
public class AgentState {

    private int row;
    private int col;
    private Orientation orientation;

    public AgentState(int row, int col, Orientation orientation) {
        this.row = row;
        this.col = col;
        this.orientation = orientation;
    }

    public int getCol() {
        return col;
    }

    public Orientation getOrientation() {
        return orientation;
    }

    public int getRow() {
        return row;
    }

    public void update(Action move) {
        if (move == Action.fwd) {
            switch (orientation) {
                case North: {
                    row--;
                    break;
                }
                case East: {
                    col++;
                    break;
                }
                case West: {
                    col--;
                    break;
                }
                case South: {
                    row++;
                    break;
                }

            }
        } else {
            orientation = Orientation.turn(orientation, move);
        }

    }

    public AgentState clone(Action move) {
        AgentState s = new AgentState(row, col, orientation);
        //TODO: make a sentry Factory, that gives 1 of n possible sentries
        s.update(move);
        return s;
    }

    public Tile getTile() {
        return Enviroment.env.map[row][col];
    }

    @Override
    public boolean equals(Object obj) {
        final AgentState other = (AgentState) obj;
        if (this.row != other.row) {
            return false;
        }
        if (this.col != other.col) {
            return false;
        }
        if (this.orientation != other.orientation) {
            return false;
        }
        return true;
    }

    @Override
    public int hashCode() {
        int hash = 7;
        hash = 47 * hash + this.row;
        hash = 47 * hash + this.col;
        hash = 47 * hash + this.orientation.hashCode();
        return hash;
    }
    
    
    
    
}
